import { defineStore } from 'pinia'
import { TOKEN_KEY } from '@/constants'
import { ref, computed } from 'vue'
import Cookies from 'js-cookie'
export const useUserStore = defineStore('hm-user', () => {
  const token = ref(Cookies.get(TOKEN_KEY) || '')
  const setToken = (newToken: string) => {
    token.value = newToken
    Cookies.set(TOKEN_KEY, newToken)
  }
  const removeToken = () => {
    token.value = ''
    Cookies.remove(TOKEN_KEY)
  }
  return {
    token,
    setToken,
    removeToken
  }
})
